package com.broada.apm.service;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import com.broada.apm.ajax.IndicatorResult;
import com.broada.apm.ajax.MenuResult;
import com.broada.apm.ajax.PerformanceResult;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@Path("apm/node")
@Api(value="apm/node" , description = "指标相关的APIs")
@Produces(MediaType.APPLICATION_JSON)
public interface IndicatorService {

	/**
	 * @Title: queryMenus
	 * @Description:
	 * @param @param nodeId
	 * @param @return
	 * @return Result
	 * @throws
	 */
	@GET
	@Path("/menus")
	@ApiOperation(value = "查询业务节点的菜单")
	@Produces(MediaType.APPLICATION_JSON)
	public MenuResult queryMenus(@ApiParam(value = "业务节点id", required = true) @QueryParam("nodeId") String nodeId);

	/**
	 * @Title: queryMenuColumns
	 * @Description:
	 * @param @param menuId
	 * @param @return
	 * @return Result
	 * @throws
	 */
	@GET
	@Path("/menus/columns")
	@ApiOperation(value = "查询菜单列")
	@Produces(MediaType.APPLICATION_JSON)
	public MenuResult queryMenuColumns(@ApiParam(value = "菜单id", required = true) @QueryParam("menuId") int menuId);

	/**
	 * @Title: queryMenuData
	 * @Description:
	 * @param @param menuId
	 * @param @param nodeId
	 * @param @return
	 * @return Result
	 * @throws
	 */
	@GET
	@Path("/menus/data")
	@ApiOperation(value = "查询数据项")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryMenuData(
			@ApiParam(value = "applicationId", required = true) @QueryParam("applicationId") String applicationId, 
			@ApiParam(value = "agentId", required = true) @QueryParam("agentId") String agentId,
			@ApiParam(value = "菜单id", required = true) @QueryParam("menuId") int menuId, 
			@ApiParam(value = "关键词key", required = false) @QueryParam("dataKey") String dataKey,
			@ApiParam(value = "关键词value", required = false) @QueryParam("dataId") String dataId, 
			@ApiParam(value = "关键词", required = false) @QueryParam("keyWord") String keyWord,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate,
			@ApiParam(value = "排序字段", required = false) @QueryParam("orderBy") String orderBy, 
			@ApiParam(value = "排序顺序，升序或降序，true为降序", required = false) @QueryParam("desc")  boolean desc,
			@ApiParam(value = "页码", required = true) @QueryParam("pageIndex") int pageIndex, 
			@ApiParam(value = "每页显示的查询记录数", required = true) @QueryParam("pageSize") int pageSize);

	@GET
	@Path("/errors")
	@ApiOperation(value = "查询业务交易的错误列表")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryTradeErrorCode(
			@ApiParam(value = "applicationId", required = true) @QueryParam("applicationId") String applicationId, 
			@ApiParam(value = "agentId", required = true) @QueryParam("agentId") String agentId,
			@ApiParam(value = "关键词", required = false) @QueryParam("keyWord") String keyWord, 
			@ApiParam(value = "页码", required = true) @QueryParam("pageIndex") int pageIndex,
			@ApiParam(value = "每页显示的查询记录数", required = true) @QueryParam("pageSize") int pageSize, 
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate,
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate);

	@GET
	@Path("/error/stack")
	@ApiOperation(value = "查询业务交易错误ID列表")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryTradeErrorStack(
			@ApiParam(value = "applicationId", required = true) @QueryParam("applicationId") String applicationId, 
			@ApiParam(value = "agentId", required = true) @QueryParam("agentId") String agentId,
			@ApiParam(value = "uri", required = true) @QueryParam("uri") String uri, 
			@ApiParam(value = "返回码", required = true) @QueryParam("errorCode") String errorCode,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate);

	@GET
	@Path("/error/stack/{errorId}")
	@ApiOperation(value = "根据错误交易id查询业务交易错误详情")
	@Produces(MediaType.APPLICATION_JSON)
	public IndicatorResult queryTradeErrorStack(
			@ApiParam(value = "错误交易id", required = true) @PathParam("errorId") String errorId,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate);

	@GET
	@Path("/indicators")
	@ApiOperation(value = "查询自定义指标项")
	@Produces(MediaType.APPLICATION_JSON)
	public IndicatorResult queryIndicators(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "拓扑节点id", required = true) @QueryParam("nodeId") String nodeId, 
			@ApiParam(value = "用以区分交易模式和非交易模式，其值可为system或business", required = true) @QueryParam("panelId") String panelId);
	
	/**
	 * 保存节点、交易等资源需要显示的自定义指标项关系
	 * 
	 * @param app
	 */
	@PUT
	@Path("/indicators/{targetId}/{panelId}")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "保存节点需要显示的自定义指标项关系")
	public IndicatorResult updateResShowIndicator(
			@ApiParam(value = "拓扑节点id", required = true) @PathParam("targetId") String targetId, 
			@ApiParam(value = "用以区分交易模式和非交易模式，其值可为system或business", required = true) @PathParam("panelId") String panelId, 
			@ApiParam(value = "需要保存的指标项id", required = true) List<Integer> metricIds);
	
	
	/**
	 * 导出CVS
	 * @Title: queryMenuData
	 * @Description:
	 * @param @param menuId
	 * @param @param nodeId
	 * @param @return
	 * @return Result
	 * @throws
	 */
	@GET
	@Path("/menus/downloadCVSData")
	@ApiOperation(value = "导出csv")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult downloadCVSData(@Context HttpServletRequest request, @Context HttpServletResponse response,
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "拓扑节点id", required = true) @QueryParam("nodeId") String nodeId,
			@ApiParam(value = "菜单id", required = true) @QueryParam("menuId") int menuId, 
			@ApiParam(value = "关键词key", required = false) @QueryParam("dataKey") String dataKey,
			@ApiParam(value = "关键词value", required = false) @QueryParam("dataId") String dataId, 
			@ApiParam(value = "关键词", required = false) @QueryParam("keyWord") String keyWord,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate,
			@ApiParam(value = "排序字段", required = false) @QueryParam("orderBy") String orderBy, 
			@ApiParam(value = "排序顺序，升序或降序，true为降序", required = false) @QueryParam("desc")  boolean desc) throws Exception;
}
